import Vue from 'vue'
import url from './api.js';
import Json from './Json' //测试用数据
// import store from '../store'
// var common = require('./common.js');
// let origin = "http://192.168.199.33:9999";


let http = new Vue({
	// ...mapMutations(['commonData']),
	methods: {
		publicRequest(method, url, body, sucFunc, failFunc) {
			let _self = this;
			uni.request({
				method: method,
				url: origin + url, //仅为示例，并非真实接口地址。
				data: body,
				success: function(res) {
					console.log(res)
				},
				fail: function(res) {
					failFunc(res);
				}
			});
		},
		publicJson(method, url, body, sucFunc, failFunc,keyword){
			console.log('xxxxadsadsad')
			this.jsons(keyword).then(tabJson => {
				if(tabJson){
					sucFunc(tabJson)
				}else{
					failFunc({
						data:'',
						code:1,
						msg:'暂无信息'
					})
				}
			})
		},
		
		jsons(keyword){
			return new Promise(resolve=>{
				setTimeout(()=>{
					resolve(Json[keyword]);
				}, 500)
			})
		},
		filterUrl(data, url) {
			for (let key in data) {
				let keys = "{" + key + "}";
				url = url.replace(keys, data[key])
			}
			return url;
		}
	},

})

export default http;
